package com.wandian.cqcsk.adapter.rank;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.makeramen.roundedimageview.RoundedImageView;
import com.mylib.libcore.utils.GlideUtil;
import com.wandian.cqcsk.R;
import com.wandian.setting.bean.RankDataBean;

/**
 * @author Administrator
 * @date 2019/12/16-13:32
 * @description RankingPageRecycleAdapter
 **/
public class RankingPageRecycleAdapter extends BaseQuickAdapter<RankDataBean, BaseViewHolder> {
    private String title="";
    public RankingPageRecycleAdapter(int layoutResId,String title) {
        super(layoutResId);
        this.title = title;
    }


    @Override
    protected void convert(BaseViewHolder helper, RankDataBean item) {

        ImageView iv_ranking_icon =helper.getView(R.id.iv_ranking_icon);
        ImageView iv_ranking_number =helper.getView(R.id.iv_ranking_number);
        ImageView iv_ranking_one =helper.getView(R.id.iv_ranking_one);

        TextView tv_rank_gold = helper.getView(R.id.tv_rank_gold);
        TextView tv_rank_title = helper.getView(R.id.tv_rank_title);
        TextView tv_rank_num = helper.getView(R.id.tv_rank_num);
        setTitleRank(title,tv_rank_title,tv_rank_num,item.getNum()+"");

        RoundedImageView iv_user_head = helper.getView(R.id.iv_user_head);
        TextView tv_user_jj = helper.getView(R.id.tv_user_jj);
        TextView tv_user_name = helper.getView(R.id.tv_user_name);
        TextView tv_user_id = helper.getView(R.id.tv_user_id);
        GlideUtil.intoHeadImg(mContext,item.getHeadPic(),iv_user_head);
        tv_user_jj.setText(""+item.getDescription());
        tv_user_name.setText(""+item.getNickName());
        tv_user_id.setText("ID:"+item.getId());

        iv_ranking_one.setVisibility(View.GONE);
        double coinNum = (4+(100-helper.getLayoutPosition())/100.0);
        tv_rank_gold.setText("今日排名奖励:"+coinNum+"金币");
        if(helper.getLayoutPosition() == 0){
            iv_ranking_icon.setImageResource(R.drawable.img_ranking_red_icon);
            iv_ranking_number.setImageResource(R.drawable.img_rank_icon_top_1);
        }else {
            iv_ranking_one.setImageResource(R.drawable.icon_rank_1);
            iv_ranking_icon.setImageResource(R.drawable.img_ranking_line_icon);

            if(helper.getLayoutPosition()+1>=10){
                iv_ranking_one.setVisibility(View.VISIBLE);
                setImgNum(iv_ranking_number,(helper.getLayoutPosition()+1)%10);
                setImgNum(iv_ranking_one,(helper.getLayoutPosition()+1)/10);
            }else {
                setImgNum(iv_ranking_number,helper.getLayoutPosition()+1);
            }

        }
    }

    private void  setTitleRank(String title,TextView tv_rank_title,TextView tvNum,String num){
        switch (title.trim()){
            case "活跃榜":
                tv_rank_title.setText("活跃时长:");
                tvNum.setText(num+"分钟");
                break;
            case "战力榜":
                tv_rank_title.setText("战力指数:");
                tvNum.setText(num+"");
                break;
            case "闯关榜":
                tv_rank_title.setText("闯关数:");
                tvNum.setText(num+"关");
                break;
            case "等级榜":
                tv_rank_title.setText("等级:");
                tvNum.setText(num+"级");

                break;
        }
    }

    private void setImgNum(ImageView iv_ranking_number,int number){
        switch (number){
            case 0:
                iv_ranking_number.setImageResource(R.drawable.icon_rank_0);
                break;
            case 1:
                iv_ranking_number.setImageResource(R.drawable.icon_rank_1);
                break;
            case 2:
                iv_ranking_number.setImageResource(R.drawable.icon_rank_2);
                break;
            case 3:
                iv_ranking_number.setImageResource(R.drawable.icon_rank_3);
                break;
            case 4:
                iv_ranking_number.setImageResource(R.drawable.icon_rank_4);
                break;
            case 5:
                iv_ranking_number.setImageResource(R.drawable.icon_rank_5);
                break;
            case 6:
                iv_ranking_number.setImageResource(R.drawable.icon_rank_6);
                break;
            case 7:
                iv_ranking_number.setImageResource(R.drawable.icon_rank_7);
                break;
            case 8:
                iv_ranking_number.setImageResource(R.drawable.icon_rank_8);
                break;
            case 9:
                iv_ranking_number.setImageResource(R.drawable.icon_rank_9);
                break;
        }
    }

}
